package game;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;

public class LoaderFile extends Scene
{
	Font font;
	int indexImagemCarregando = 0;
	String strCarregando = "Loading";
	FontMetrics fm;
	int fontWidth;
	float time = 0;
	float sTime = 0;
	
	
	public LoaderFile()
	{
		LoadFonte.getInstance().Load();
		font = LoadFonte.getFonte(1);
	}
	
	@Override
	public void update() 
	{
		time += Time.getInstance().getLoopTime();
		
		float dTime = 0.05f;
		
		if(time >= sTime + dTime)
		{
			time = sTime + dTime;
			
			this.strCarregando = this.strCarregando + ".";
			
			if(time >= dTime*5)
			{
				time = 0;
				this.strCarregando = "Loading";
			}
			
			sTime = time + dTime;
		}
		
	}

	@Override
	public void draw(Graphics2D g2d) 
	{
		
		if(this.indexImagemCarregando < Audios.getInstance().stSounds.length)
		{
			Audios.getInstance().stopAll();
		}
		
		g2d.drawImage(LoadImages.getImage(this.indexImagemCarregando), 1000, 1000, 10000, 10000, null);
		g2d.setColor(Color.BLACK);
		g2d.fillRect(0, 0, Game.screenWidth, Game.screenHeigth);
		g2d.setColor(Color.WHITE);
		g2d.setFont(font);
		
		
		
		fm = g2d.getFontMetrics();
		this.fontWidth = fm.stringWidth("Loading");
		g2d.drawString(this.strCarregando, (int)((Game.screenWidth - this.fontWidth) * 0.5f), 280);
		
		
		this.indexImagemCarregando++;
		
		if(this.indexImagemCarregando >= LoadImages.stImages.length)
			SceneManager.changeScene(0);
	}
}
